﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RBOSS.Business.AdminModule;

namespace RBOSS.WebUI
{
    public partial class EditRoles : System.Web.UI.Page
    {
        Roles_sys us = new Roles_sys();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RolesList1.Items.Add("New Role");
                us = new Roles_sys();
                ListItem lstItems;
                Dictionary<string, string> obj = us.getRoles();
                foreach (string item in obj.Keys)
                {
                    lstItems = new ListItem(obj[item], item);
                    RolesList1.Items.Add(lstItems);
                }

                RolesList1.SelectedIndex = -1;
            }
        }

        protected void RolesList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Roles_sys role = us.getselectedRoles(int.Parse(RolesList1.SelectedValue));
            txtRoleName.Text = role.RoleName;
            TextBox1.Text = role.Description;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (RolesList1.Text == "New Role")
            {
                us.AddRole(txtRoleName.Text, TextBox1.Text);
            }
            else
            {
                us.editrole(int.Parse(RolesList1.SelectedValue), txtRoleName.Text, TextBox1.Text);
            }
        }
    }
}